import random

def gate(change:bool,times:int)->float:
    '''假设主持人知道哪个选项有奖励，一定选择没有奖励的选项'''
    win = 0
    for i in range(times):
        rare = random.randint(1,3)
        choose = random.randint(1,3)
        box = [1,2,3]
        if choose == rare:
            box.remove(rare)
            passed = box[random.randint(0,1)]
            box = [1,2,3]
            box.remove(passed)
            if change == True:
                box.remove(choose)
                choose = box[0]
        else:
            box.remove(choose)
            box.remove(rare)
            passed = box[0]
            box = [1,2,3]
            box.remove(passed)
            if change == True:
                box.remove(choose)
                choose = box[0]

        if choose == rare:
            win = win +1
    return win/times


def gate2(change:bool,times:int):
    '''假设主持人不知道哪个箱子有奖励，当主持人选中奖励后，记作坏事件，在所有的好事件中，改不改变选项，不会提升概率'''
    win = 0
    bad = 0
    for i in range(times):
        rare = random.randint(1,3)
        choose = random.randint(1,3)
        box = [1,2,3]
        box.remove(choose)
        passed = box[random.randint(0,1)]
        if passed == rare:
            bad = bad +1
            continue
        else:
            if change == True:
                box = [1,2,3]
                box.remove(passed)
                box.remove(choose)
                choose = box[0]
            if choose == rare:
                win = win +1
    return bad, win, win/(times-bad)



# 如果主持人知情
# 改变选择胜利的概率为66.7%
print(gate(True,100000))
print(gate(False,100000))

# 如果主持人不知情
# 会有50%的概率导致游戏无法进行，若可以进行，则改不改变选择不会提升概率
print(gate2(True,100000))
print(gate2(False,100000))